const express = require('express')
const app = express()
const db = require('./models')
const uploadRoute = require('./api/upload')
const dptRoute = require('./api/department')
const staffRoute = require('./api/staff')
const clientRoute = require('./api/client')
const loginRoute = require('./api/login')
const factoryRoute = require('./api/factory')
const productRoute = require('./api/product')
const projectRoute = require('./api/project')
const problemRoute = require('./api/problem')
const contractRoute = require('./api/contract')
const implementRoute = require('./api/implement')
const shopRoute = require('./api/shop')
const contractPaymemt = require('./api/contractPayment')
const messageRoute = require('./api/message')
const opportunityRoute = require('./api/opportunity')
const inventoryRoute = require('./api/inventory')
const receiptRoute = require('./api/receipt')
const serviceRoute = require('./api/service')
const serviceDocRoute = require('./api/serviceDoc')


const cors = require('cors')

require('dotenv').config()

app.use(cors())
app.use(express.urlencoded({ extended: true }))
app.use(express.json({limit: '50mb'}))
app.use('/download',express.static('uploads'))

app.use('/upload',uploadRoute)
app.use('/department', dptRoute)
app.use('/staff', staffRoute)
app.use('/login',loginRoute)
app.use('/client',clientRoute)
app.use('/factory',factoryRoute)
app.use('/product',productRoute)
app.use('/project',projectRoute)
app.use('/problem',problemRoute)
app.use('/contract',contractRoute)
app.use('/implement',implementRoute)
app.use('/shop',shopRoute)
app.use('/payment',contractPaymemt)
app.use('/message',messageRoute)
app.use('/opportunity',opportunityRoute)
app.use('/inventory',inventoryRoute)
app.use('/receipt',receiptRoute)
app.use('/service',serviceRoute)
app.use('/servicedoc',serviceDocRoute)

const conf = process.env
console.log(conf.NODE_ENV); 
db.sequelize.sync({ alter: true }).then(() => {
    app.listen(conf.PORT, () => {
        console.log(`Server has started on port ${conf.PORT}`)
    })
}).catch(err=>{
    console.error(err)
})